package com.yuanye.gwcit.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class ScreenPanelActivity extends AppCompatActivity {


    TextView tvColorPanel;
    private int[] colors = {Color.RED, Color.GREEN, Color.BLUE, Color.WHITE, Color.GRAY, Color.BLACK};
    int colorId = 0;
    private boolean switchEnable = false;
    Handler handler;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        tvColorPanel = new TextView(this);
        getSupportActionBar().hide();
        setContentView(tvColorPanel);
        handler = new Handler();
        tvColorPanel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tvColorPanel.post(new Runnable() {
                    @Override
                    public void run() {
                        if (switchEnable){
                            if (++colorId == colors.length){
                                setResult(200);
                                finish();
                            }else{
                                tvColorPanel.setBackgroundColor(colors[colorId]);
                                switchDelay();
                            }
                        }

                    }
                });
            }
        });
        tvColorPanel.setBackgroundColor(colors[colorId]);
        switchDelay();
    }

    private void switchDelay(int sec){
        switchEnable = false;
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                switchEnable = true;
            }
        }, sec*1000);
    }

    private void switchDelay(){
        switchDelay(1);
    }
}
